<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'personal.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script src="${pageContext.request.contextPath}/js/getmd5.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	function asubmit() {
		if(validate()){
			$.ajax({
				url : "${pageContext.request.contextPath}/login/updatePassword.action",
				data : "user.pwd=" + hex_md5($("#check2").val()),
				success : function(data) {
					alert(data.json.msg);
				}
			});
		}else{
			alert("请按提示正确输入密码！");
		}
	}
	function checkPassword(obj) {
		$.ajax({
			url : "${pageContext.request.contextPath}/login/checkPassword.action",
			data : "user.pwd=" + hex_md5(obj.value),
			success : function(data) {
				$("#span").text(data.json.msg);
				if(obj.value==''){
					$("#span").text("");
				}
			}
		});
		
	}
	function validate(){
		var flag = false;
		var text = $("#span").text();
		if(text=="yes"){
			flag=true;
			var check1 = $("#check1").val();
			var check2 = $("#check2").val();
			if (check1 != '' && check2 != '') {
				if (check1 != check2) {
					$("#span1").text("yes");
					$("#span2").text("no");
					flag=false;
				} else {
					$("#span1").text("yes");
					$("#span2").text("yes");
					flag=true;
				}
			}else if (check1 != '') {
				$("#span1").text("yes");
				$("#span2").text("no");
				flag=false;
			} else if (check2 != '') {
				$("#span1").text("no");
				$("#span2").text('');
				flag=false;
			} else if (check1 == '' && check2 == '') {
				$("#span1").text('');
				$("#span2").text('');
				flag=false;
			}
		}else{
			var check1 = $("#check1").val();
			var check2 = $("#check2").val();
			if (check1 != '' && check2 != '') {
				if (check1 != check2) {
					$("#span1").text("yes");
					$("#span2").text("no");
					flag=false;
				} else {
					$("#span1").text("yes");
					$("#span2").text("yes");
					flag=true;
				}
			}else if (check1 != '') {
				$("#span1").text("yes");
				$("#span2").text("no");
				flag=false;
			} else if (check2 != '') {
				$("#span1").text("no");
				$("#span2").text('');
				flag=false;
			} else if (check1 == '' && check2 == '') {
				$("#span1").text('');
				$("#span2").text('');
				flag=false;
			}
			flag=false;
		}
		if(flag==true){
			
		}
		return flag;
	}
</script>

</head>

<body>
	
		<table>
			<caption>修改密码</caption>
		
			<tbody>
			<form action="javascript:void(0);">
					<tr>
						<td>旧密码</td>
						<td><input type="password" onchange="checkPassword(this)" id="check"/>
						<td><span id="span"></span>
					</tr>
					<tr>
						<td>新密码</td>
						<td><input type="password" onchange="validate()" id="check1" />
						<td><span id="span1"></span>
					</tr>
					<tr>
						<td>确认密码</td>
						<td><input type="password" onchange="validate()" id="check2" />
						<td><span id="span2"></span>
					</tr>
					<tr>
						<td colspan="2"><button onclick="asubmit()">保存</button></td>
					</tr>
				</form>
			</tbody>
		</table>
	
</body>
</html>
